package com.quectel.core.module.device.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.quectel.core.module.device.dto.datav.DeviceCountDto;
import com.quectel.core.module.device.dto.datav.DeviceTypeCountDto;
import com.quectel.core.module.device.entity.DeviceEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @author rananxin
 * @date 2021-10-29 13:49:56
 */

public interface DeviceDao extends BaseMapper<DeviceEntity> {

    List<DeviceEntity> queryAtlasBindDevices(Map<String, Object> params);

    DeviceCountDto countDevice(Map<String, Object> params);

    List<DeviceTypeCountDto> countDeviceType(Map<String, Object> params);

    /**
     * 查询列表
     *
     * @param params
     * @return
     */
    List<DeviceEntity> queryList(Map<String, Object> params);

    /**
     * 查询数量
     *
     * @param params
     * @return
     */
    int queryTotal(Map<String, Object> params);


    int queryTreeTotal(Map<String, Object> params);

    List<DeviceEntity> queryTreeRootList(Map<String, Object> params);

    @Select("<script>with recursive temp as (select * from device a where a.id = #{deviceId} " +
            "union select b.* from device b " +
            "INNER JOIN temp t on b.parent_id = t.id) " +
            "select * from temp where id != #{deviceId}</script>")
    List<DeviceEntity> queryByParent(@Param("deviceId") Long deviceId);
}
